﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraReports.UI;

namespace IT_Pro.Forms
{
    public partial class frmThongKeNhanVien : DevExpress.XtraEditors.XtraForm
    {
        public frmThongKeNhanVien()
        {
            InitializeComponent();
        }

        private void LoadDSPhongvaoCBO()
        {
            DataTable dt = Class.NV_PhongBan.HienThiDsPhong();
            dt.Rows.InsertAt(dt.NewRow(), 0);
            dt.Rows[0]["MaPhong"] = 0;
            dt.Rows[0][1] = "Tất cả";
            cboPhongBan.Properties.DataSource = dt;
            cboPhongBan.Properties.ValueMember = "MaPhong";
            cboPhongBan.Properties.DisplayMember = "TenPhong";
            cboPhongBan.EditValue = 0;
        }

        private void frmThongKeNhanVien_Load(object sender, EventArgs e)
        {
            LoadDSPhongvaoCBO();
        }

        private void loaddsNV(int phong)
        {
            gridTKDTCSHT.DataSource = Class.TK_ThongKe.LoadDsDTCSHT(phong);
            gridTKBanGiao.DataSource = Class.TK_ThongKe.LoadDsBanGiao(phong);
        }

        private void btnXemNVTheoPhong_Click(object sender, EventArgs e)
        {
            loaddsNV(int.Parse(cboPhongBan.EditValue.ToString()));
        }

        private void checkShowCode_CheckedChanged(object sender, EventArgs e)
        {
            if (checkShowCode.Checked)
            {
                txtItemCode.PasswordChar = '\0';

            }
            else
            {
                txtItemCode.PasswordChar = '*';
            }
        }

        private void mnInBanGiao_Click(object sender, EventArgs e)
        {

            int SelectedRow = gridDSTKBG.FocusedRowHandle;
            if (SelectedRow >= 0)
            {
                DataRow drow = gridDSTKBG.GetDataRow(SelectedRow);
                string _value = drow["MaMay"].ToString();
                if (_value.Length > 2)
                {
                    Class.Print_Report print = new Class.Print_Report();
                    print.Mamay = _value;
                    DataTable dt = print.R_BanGiaoThietBi();
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            dt.Rows[i][0] = i + 1;
                        }
                    }
                    Reports.R_BanGiaoThietBi rbg = new Reports.R_BanGiaoThietBi();
                    rbg.DataSource = dt;
                    rbg.ShowPreview();
                }
            }
        }

        private void gridDSTKBG_DoubleClick(object sender, EventArgs e)
        {
              int SelectedRow = gridDSTKBG.FocusedRowHandle;
              if (SelectedRow >= 0)
              {
                  DataRow drow = gridDSTKBG.GetDataRow(SelectedRow);
                  string _value = drow["MaMay"].ToString();
                  if (_value.Length > 2)
                  {
                      frmMayViTinh_ChiTiet frm = new frmMayViTinh_ChiTiet(_value);
                      frm.ShowDialog();
                  }

              }
        }
    }
}